package com.mdx.user;

import com.mdx.common.base.CommonResponse;

import java.util.Arrays;

/**
 * @author : jiagang
 * @date : Created in 2024/3/26 17:41
 */
public class LeetCodeDay1 {

    public static void merge(int[] nums1, int m, int[] nums2, int n) {
        int p1 = 0, p2 = 0;
        int cur;
        int[] sorted = new int[m + n];
        while (p1 < m || p2 < n) {
            if (p1 == m) {
                cur = nums2[p2++];
            } else if (p2 == n) {
                cur = nums1[p1++];
            } else if (nums1[p1] < nums2[p2]) {
                cur = nums1[p1++];
            } else {
                cur = nums2[p2++];
            }
            sorted[p1 + p2 - 1] = cur;
        }
        for (int i = 0; i != m + n; ++i) {
            nums1[i] = sorted[i];
        }
        System.out.println(Arrays.toString(nums1));
    }

    public static int removeElement(int[] nums, int val) {
        int left = 0;
        int right = nums.length;
        while (left < right){
            if (nums[left] == val){
                nums[left] = nums[right -1];
                right --;
            }else {
                left ++;
            }
        }
        return left;
    }
    // r = 1  l = 1
    // 2 2
    public static void main(String[] args) {
        //int[] m = {1, 2, 3, 0, 0, 0};
        //int[] n = {2, 5, 6};
        //merge(m, 3, n, 3);

        int[] num = {3,2,2,3};
        System.out.println(removeElement(num, 3));
    }

}
